/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.audit.mapper;

import com.koron.audit.domain.Audit;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface AuditMapper {
    /**
     * 根据主键获取审批记录详情
     *
     * @param id
     * @return
     */
    Audit queryOne(@Param("id") String id);

    /**
     * 根据指定条件查询审批记录列表
     *
     * @param title
     * @param flowName
     * @param state
     * @param addTimeStart
     * @param addTimeEnd
     * @param start
     * @param rows
     * @return
     */
    List<Audit> queryByCondition(@Param("code") String code, @Param("title") String title, @Param("flowName") String flowName, @Param("state") Integer state, @Param("addTimeStart") Date addTimeStart,
                                 @Param("addTimeEnd") Date addTimeEnd, @Param("start") Integer start, @Param("rows") Integer rows);

    /**
     * 根据指定条件统计审批记录的数量
     *
     * @param title
     * @param flowName
     * @param state
     * @param addTimeStart
     * @param addTimeEnd
     * @return
     */
    Integer countByCondition(@Param("code") String code, @Param("title") String title, @Param("flowName") String flowName, @Param("state") Integer state, @Param("addTimeStart") Date addTimeStart,
                             @Param("addTimeEnd") Date addTimeEnd);

    List<Audit> queryByIdList(@Param("idList") List<String> idList, @Param("code") String code, @Param("title") String title, @Param("flowName") String flowName,
                              @Param("state") Integer state, @Param("addTimeStart") Date addTimeStart, @Param("addTimeEnd") Date addTimeEnd,
                              @Param("start") Integer start, @Param("rows") Integer rows, @Param("keyword") String keyword);

    Integer countByIdList(@Param("idList") List<String> idList, @Param("code") String code, @Param("title") String title, @Param("flowName") String flowName,
                          @Param("state") Integer state, @Param("addTimeStart") Date addTimeStart, @Param("addTimeEnd") Date addTimeEnd, @Param("keyword") String keyword);

    /**
     * 新增审批记录
     *
     * @param audit
     * @return
     */
    Integer insert(@Param("audit") Audit audit);

    /**
     * 批量新增审批记录
     *
     * @param auditList
     * @return
     */
    Integer batchInsert(@Param("auditList") List<Audit> auditList);

    /**
     * 修改审批记录
     *
     * @param audit
     * @return
     */
    Integer update(@Param("audit") Audit audit);

    /**
     * 批量修改审批记录
     *
     * @param auditList
     * @return
     */
    Integer batchUpdate(@Param("auditList") List<Audit> auditList);

    /**
     * 根据主键删除审批记录
     *
     * @param id
     * @return
     */
    Integer delete(@Param("id") String id);
    /**
     * 查询发起的任务
     *
     * @param initiatorCode
     * @return
     */
    List<Audit> queryByInitiator(@Param("initiatorCode") String initiatorCode, @Param("code") String code, @Param("title") String title, @Param("flowName") String flowName, @Param("state") Integer state, @Param("addTimeStart") Date addTimeStart,
                                 @Param("addTimeEnd") Date addTimeEnd, @Param("start") Integer start, @Param("rows") Integer rows,@Param("keyword") String keyword);

    /**
     * 统计发起的任务数量
     *
     * @param initiatorCode
     * @return
     */
    Integer countByInitiator(@Param("initiatorCode") String initiatorCode, @Param("code") String code, @Param("title") String title, @Param("flowName") String flowName, @Param("state") Integer state,
                             @Param("addTimeStart") Date addTimeStart, @Param("addTimeEnd") Date addTimeEnd,@Param("keyword") String keyword);

    @Select("select * from tbl_audit where flow_instance_id=#{processInstId}")
    Audit queryByProcessId(@Param("processInstId") String processInstId);

    /**
     * 根据关联业务id,模板key查询审批记录列表
     *
     * @param businessIds
     * @param templateKey
     * @return
     */
    List<Audit> queryListByBusinessIds(@Param("businessIds") String businessIds, @Param("templateKey") String templateKey);

    /**
     * 根据工作流实例id查询审批列表
     *
     * @param processIdList
     * @param code
     * @param title
     * @param flowName
     * @param state
     * @param addTimeStart
     * @param addTimeEnd
     * @param start
     * @param rows
     * @return
     */
    List<Audit> queryByProcessIdList(@Param("processIdList") List<String> processIdList, @Param("code") String code, @Param("title") String title, @Param("flowName") String flowName,
                                     @Param("state") Integer state, @Param("addTimeStart") Date addTimeStart, @Param("addTimeEnd") Date addTimeEnd,
                                     @Param("start") Integer start, @Param("rows") Integer rows);

    Integer countByProcessIdList(@Param("processIdList") List<String> processIdList, @Param("code") String code, @Param("title") String title, @Param("flowName") String flowName,
                                 @Param("state") Integer state, @Param("addTimeStart") Date addTimeStart, @Param("addTimeEnd") Date addTimeEnd);

    Audit queryByBusinessIds(@Param("businessIds") String businessIds, @Param("updateTime") Date updateTime);

    Audit getAuditByBusinessId(@Param("businessId") String businessId);


    List<String> getAuditCodeByBusinessId(@Param("businessIds") List<String> businessIds);

    List<String> getAuditIdByBusinessId(@Param("businessId") String  businessId);

    Integer batchDetele(@Param("codeList") List<String> codeList);
}
